<template>
	<view>
		<view class="interconnect-view">
			<u-navbar :background="background" back-icon-color="#FFFFFF">
			</u-navbar>
			<view class="user-image">
				<image style="width: 100%;height: 100%;" :src="avatarUrl" mode=""></image>
			</view>
			<view class="user-name">
				{{anotherUserName}}
			</view>
			<button class="btn-yq" type="default" @tap.stop="getUserDataIF()">接受邀请</button>
		</view>

	</view>
</template>

<script>

import uNavbar from "@/uview-ui/components/u-navbar/u-navbar.vue"

	export default {
		components: {
			uNavbar,
		},
		data() {
			return {
				userInfo: [],
				code: '', //微信登录code码
				encryptedData: '',
				iv: '',
				isBindPhone: false, //绑定手机号弹框
				avatarUrl: '',
				anotherUserId: '',
				anotherUserName: '',
				yqcode: '',
				background: {
					backgroundImage: 'linear-gradient(10deg, rgb(129, 192, 66,0), rgb(46, 167, 224,0))'
				},
			}
		},
		onLoad(e) {
			if(e.code){//亲友data
			uni.setStorageSync('dearData',e)
			}else{//没有情况获取存储
				e = uni.getStorageSync('dearData')
			}
			this.avatarUrl = e.avatarUrl;
			this.anotherUserId = e.anotherUserId;
			this.anotherUserName = e.anotherUserName;
			this.yqcode = e.code;
		},
		methods: {
			// 判断用户本地是否有登录信息
			getUserDataIF() {
				this.$basejs.globaltoken()//判断当前是否登录
				this.invitation()
			},
			//请求登录
			login() {
				let _this = this;
				this.$api.post(global.apiUrls.login, {
						userSource: 1, //用户类型 1:C端用户  2:员工
						avatarUrl: _this.userInfo.avatarUrl, //头像
						code: _this.code, //微信登录code
						gender: _this.userInfo.gender, //性别
						nickName: _this.userInfo.nickName, //昵称
						city: _this.userInfo.city, //微信所在的城市
						country: _this.userInfo.country, //微信所在的国家
						language: _this.userInfo.language, //微信用户语言
						province: _this.userInfo.province, //微信用户所在省份
						iv: _this.iv, //手机号密文
						encryptedData: _this.encryptedData, //手机号密文
					})
					.then(res => {

						if (res.data.code == 1000) {
							let loginKey = global.IS_DEV?'USER_TOKEN_BSY_T':'USER_TOKEN_BSY_Z'
							uni.setStorageSync(loginKey, res.data.result.refreshToken);
							uni.setStorageSync(loginKey, res.data.result)
							_this.invitation()
						} else {}
					}).catch(err => {
						console.log(err)
					})
			},
			// 接收邀请
			invitation() {
				let fdata = {
					anotherUserId: uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').userId, //被邀请id
					anotherUserName: uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').nickName,
					code: this.yqcode,
					userId: this.anotherUserId //邀请人id
				}
				console.log(fdata, 13777777)
				this.$api.post(global.apiUrls.invitation, fdata).then(res => {
					if (res.data.code == 1000) {
						uni.showToast({
							title: res.data.message,
							duration: 2000
						});
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/tab/home',
							});
						}, 2000);
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration: 2000
						});
					}
				}).catch(err => {})
			}
		}
	}
</script>

<style lang="scss">
	.interconnect-view {
		width: 750upx;
		height: 1624upx;
		background: url(https://bsyjk-pic.bsyjk.cn/interconnect/36F2A3E13902486A88A37F97F074A942.png)no-repeat;
		background-size: 750upx 1624upx;
		position: relative;

		.user-image {
			width: 168upx;
			height: 168upx;
			background: #000;
			position: absolute;
			top: 258upx;
			left: 50%;
			transform: translateX(-50%);
			border-radius: 50%;
			overflow: hidden;
		}

		.user-name {
			width: 100vw;
			text-align: center;
			font-size: 36upx;
			font-weight: 800;
			color: #4A4A4A;
			line-height: 50upx;
			position: absolute;
			top: 431upx;

		}

		.btn-yq {
			width: 655upx;
			height: 90upx;
			background: linear-gradient(225deg, #FF8960 0%, #FF62A5 100%);
			border-radius: 45upx;
			position: fixed;
			bottom: 30upx;
			left: 50%;
			transform: translateX(-50%);
			font-size: 34upx;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 90upx;
		}
	}

	// 绑定手机号
	.phone-login {
		background-color: #FFFFFF;
		width: 600upx;
		height: 400upx;
		padding: 1upx;
		border-radius: 40upx;

		.but-boxs {
			margin-top: 90upx;
			width: 400upx;
			height: 90upx;
			border-radius: 45upx;
			background: linear-gradient(112deg, #81C042 0%, #2EA7E0 100%);
			font-size: 32upx;
			color: #FFFFFF;
			border: none;
		}

		.title-login {
			width: 600upx;
			text-align: center;
			height: 200upx;
			line-height: 200upx;
			font-size: 32upx;
			color: #333333;
		}
	}
</style>
